<template>
<div>
    <form class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">起始时间</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" style="width:350px" autocomplete="off" id="test1" placeholder="请输入起始时间">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">结束时间</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" style="width:350px" autocomplete="off" id="test2" placeholder="请输入结束时间">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit="" @click="notice" lay-filter="demo1">立即执行</button>
            </div>
        </div>
    </form>
    <div>
        <form class="layui-form" id="test" style="display:none">
            <div class="from_de">
                <div class="layui-form-item">
                    <label class="layui-form-label">用户名</label>
                    <div class="layui-input-block">
                        <input type="text" name="title" required lay-verify="required" placeholder="请输入用户" autocomplete="off" class="layui-input" id="name" style="width:200px">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">密码</label>
                    <div class="layui-input-block">
                        <input type="password" name="title" required lay-verify="required" placeholder="请输入管理员密码" autocomplete="off" class="layui-input" id="pwd" style="width:200px">
                    </div>
                </div>
            </div>

        </form>
    </div>
</div>
</template>

<script>
export default {
    name: 'Inventory1',
    data() {
        return {

        }
    },
    mounted() {
        layui.use('laydate', function () {
            var laydate = layui.laydate;
            //常规用法
            laydate.render({
                elem: '#test1'
            });
            laydate.render({
                elem: '#test2'
            });

        });

    },
    methods: {
        notice: function () {
            var time1 = $("#test1").val();
            var time2 = $("#test2").val()
            if (time1 === "") {
                this.alert("请输入起始时间")
            } else if (time2 === "") {
                this.alert("请输入结束时间")
            } else {
                layer.open({
                    type: 1,
                    area: ['700px', '250px'],
                    title: '请输入用户名与管理员密码验证',
                    content: $("#test"),
                    shade: 0,
                    btn: ['确认', '取消'],
                    btn1: function (index, layero) {
                        var name = $("#name").val();
                        var pwd = $("#pwd").val();
                        let postData = {
                            name: name,
                            pwd: pwd
                        }
                        var form = layui.form,
                            layer = layui.layer;
                        let loader = layer.load();
                        $.ajax({
                            url: '/system/Tuser!adminer.action',
                            data: postData,
                            type: "post",
                            dataType: "json",
                            success: function (res) {
                                if (res.msg == "success") {
                                    var time1 = $("#test1").val();
                                    var time2 = $("#test2").val();
                                    let postData = {
                                        starttime: time1,
                                        endtime: time2
                                    }
                                    let loader = layer.load();
                                    $.ajax({
                                        url: '/harvest/Whinfo!recoverWhinfoRecord.action',
                                        data: postData,
                                        type: "post",
                                        dataType: "json",
                                        success: function (res) {
                                            console.log(res)
                                            if (res.msg == "success") {
                                                layer.closeAll();
                                                layer.close(loader);
                                                layer.alert("每日动态库存重跑开启")
                                            } else {
                                                layer.closeAll();
                                                layer.close(loader);
                                                layer.alert(res.msg)
                                            }
                                        },
                                        complete: function () {
                                            layer.close(loader);
                                        }
                                    });
                                } else {
                                    layer.closeAll();
                                    layer.close(loader);
                                    layer.alert(res.msg)
                                }
                            },
                            complete: function () {
                                layer.close(loader);
                            }
                        });
                    },
                    btn2: function (index, layero) {
                        console.log("取消")
                        layer.closeAll();
                    },
                    cancel: function (layero, index) {
                        layer.closeAll();
                    }

                });
            }

        }
    }
}
</script>
<style scoped>
.from_de{
    position:relative;
    top:20px;
    }
</style>
